package cn.xo68.sample.mybaitsdemo.controller;

import java.util.Calendar;
import java.util.Random;


import cn.xo68.sample.mybaitsdemo.config.UUIDTools;
import cn.xo68.sample.mybaitsdemo.entity.SysUser;
import cn.xo68.sample.mybaitsdemo.service.SysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;




@RestController
public class HomeController {
	private static final Logger logger=LoggerFactory.getLogger(HomeController.class);
	@Autowired
	private SysUserService sysUserService;
	
	@GetMapping("/")
	public Page<SysUser> index() {
		
//		sysUserService.i
		
		SysUser user=new SysUser();
		user.setId(UUIDTools.createUUId());
		Random rnd=new Random();
		
		user.setAccount("user"+String.valueOf(rnd.nextInt(1000)));
		user.setCreateTime(Calendar.getInstance().getTime());
		user.setSex("男");
		user.setStatus(1);
		
		sysUserService.insert(user);
		
		Page<SysUser> page= sysUserService.selectAll();
		
		logger.debug("count:"+String.valueOf(page.getTotal()));
		logger.debug("getPageSize:"+String.valueOf(page.getPageSize()));
		logger.debug("getPageNum:"+String.valueOf(page.getPageNum()));
		
		return page;
	}
	
	@GetMapping("/getUserByAccount")
	public SysUser getUserByAccount(@RequestParam(value="account") String account) {
		return sysUserService.getUserByAccount(account);
	}
}
